package cn.edu.zafu.bigdata.psy;

abstract class Shape {
    public abstract double area();
    public abstract double perimeter();

    public final void display() {
        System.out.println("Shape type: " + getClass().getSimpleName() + ", Area: " + area() + ", Perimeter: " + perimeter());
    }
}

class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * radius * radius;
    }

    @Override
    public double perimeter() {
        return 2 * Math.PI * radius;
    }
}
class Rectangle extends Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return length * width;
    }

    @Override
    public double perimeter() {
        return 2 * (length + width);
    }
}
class TestShape {
    public static void main(String[] args) {
        Circle circle = new Circle(5);
        Rectangle rectangle = new Rectangle(4, 6);

        circle.display();
        rectangle.display();
    }
}
// 尝试创建一个 final 类，不能被继承
final class FinalClass {
    public void method() {
        System.out.println("Final class method.");
    }
}

class SubclassTryingToInheritFinalClass {
    // 这里会报错，因为 FinalClass 是 final 类不能被继承
    // public void method() {
    //     System.out.println("Trying to override in subclass.");
    // }
}

class FinalMethodClass {
    final public void finalMethod() {
        System.out.println("Final method in FinalMethodClass.");
    }
}

class SubclassOfFinalMethodClass {
    // 这里会报错，因为 final 方法不能被重写
    // public void finalMethod() {
    //     System.out.println("Trying to override final method.");
    // }
}

class FinalVariableTest {
    public static void main(String[] args) {
        final int finalVariable = 10;
        // 以下会报错，因为 final 变量不能被重新赋值
        // finalVariable = 20;
        System.out.println(finalVariable);
    }
}